home *** CD-ROM | disk | FTP | other *** search
/ CYBER.XPO.95 / CYBER.XPO.95 (Arsenal Computer).ISO / popreq / amiga1 / ddli330.lha / ddli.c < prev    next >
C/C++ Source or Header  |  1994-03-01  |  11KB  |  332 lines

  1. /*
  2.  *  ddli.c
  3.  *  The Duniho and Duniho Life Pattern Indicator
  4.  *  by Fergus Duniho
  5.  *  Copyright (c) 1992-1994 Fergus Duniho
  6.  */
  7.  
  8. #define VER "V3.30"
  9. #define EMAIL "fdnh@troi.cc.rochester.edu"
  10. #define NETMAIL "The Holodeck BBS 1:2613/336"
  11.  
  12. #undef MSDOS
  13.  
  14. #define AMIGA 1
  15. #define MSDOS 2
  16. #define OTHER 3
  17.  
  18. #define OPSYS AMIGA
  19.  
  20. #if OPSYS == AMIGA
  21.     #define prtdev "PRT:"
  22.     #define FILE_NAME_MAX 32
  23.     #define OUTMAX 3
  24.     #define OUTSTR "Send output to (1) Screen, (2) File, or (3) Printer?"
  25. #elif OPSYS == MSDOS
  26.     #define prtdev "PRN"
  27.     #define FILE_NAME_MAX 8
  28.     #define OUTMAX 3
  29.     #define OUTSTR "Send output to (1) Screen, (2) File, or (3) Printer?"
  30. #elif OPSYS == OTHER
  31.     #define prtdev ""
  32.     #define FILE_NAME_MAX 16
  33.     #define OUTMAX 2
  34.     #define OUTSTR "Send output to (1) Screen or (2) File?"
  35. #else
  36.     #error OPERATING SYSTEM UNKNOWN
  37. #endif
  38.  
  39. /*
  40.  * If your compiler does not have the command "strdup",
  41.  * which is common in C compilers but not part of ANSI
  42.  * C, uncomment the next #include statement.
  43.  */
  44. /* #include "strdup.c" */
  45.  
  46. #include "fpdio.c"
  47. #include "qst.c"
  48. #include <time.h>
  49.  
  50. #define XN E ? "Extraverted" : "Introverted"
  51. #define QFILE "DDLI.QST"
  52.  
  53. int pow (int x, int y);
  54. int typecmp (char *t1, char *t2);
  55.  
  56. int main (int argc, char **argv) {
  57.     int i, col, size, A, pr[14], x,
  58.         E, I, S, N, T, F, J, P, ES, EN, ET, EF, R;
  59.     char line[256], nline[512], *name, *fname, *type,
  60.          LP[5], LPE[5], LPI[5],
  61.          *PF[2] = {"Intuition", "Sensing"},
  62.          *JF[2] = {"Thinking", "Feeling"},
  63.          *text1 = "Your %s function is %s %s.";
  64.     FILE *fptr;
  65.     qst *Q;
  66.  
  67. #if OPSYS == MSDOS
  68.     col = 75;
  69. #else
  70.     wrapwrite (stdout, 0, 0, 20, "How many columns does your screen have?", 0);
  71.     col = fgetp(stdin);
  72. #endif
  73.  
  74.     wrapwrite (stdout, 0, 0, col,
  75.         "\n\"The Duniho and Duniho Life Pattern Indicator\"",
  76.         VER, "\nBy Fergus Duniho. Copyright (c) 1992-1994",
  77.         "Fergus Duniho.\n\nMost of the questions are drawn from",
  78.         "and based on those in Terence Duniho's \"Preference",
  79.         "Patterns Questionaire\" and his book _Wholeness Lies",
  80.         "Within_. Fergus is responsible for the choice of questions.",
  81.         "\n\nThis product is freeware. Send your raw scores and",
  82.         "sundry comments to Fergus Duniho through the Internet or",
  83.         "through the Fidonet.  Here are my Internet and Fidonet",
  84.         "addresses:\n\n", EMAIL, "\n", NETMAIL, "\n", 0);
  85.  
  86.     wrapwrite (stdout, 0, 0, col, "Hit <ENTER> to continue.\n", 0);
  87.     while (fgetc(stdin) != '\n');
  88.  
  89.     wrapwrite (stdout, 5, 0, col, "When you answer each question,",
  90.         "there are some things you should bear in mind.\n\n", 0);
  91.  
  92.     wrapwrite (stdout, 2, 0, col, "1.   Base your answer on how you usually",
  93.         "are, not just on how you were on a particular occasion.\n\n", 0);
  94.  
  95.     wrapwrite (stdout, 2, 0, col, "2.   Base your answer on how you actually",
  96.         "are, even when that differs from how you would like to be.\n\n", 0);
  97.  
  98.     wrapwrite (stdout, 2, 0, col, "3.   Base your answer on how you have",
  99.         "actually been in real situations, as opposed to how you might be",
  100.         "in imaginary situations.\n\n", 0);
  101.  
  102.     wrapwrite (stdout, 2, 0, col, "4.   Finally, remember that this is not",
  103.         "a test. Nobody has an answer key with the right answers in it.",
  104.         "The right answers depend upon who you are. This program does not",
  105.         "measure degrees of normality and abnormality. It merely measures",
  106.         "differences that may exist between normal, psychologically,",
  107.         "healthy individuals.\n\n", 0);
  108.  
  109.     size = Linefeeds(QFILE) / 3;
  110.     Q = new_qnode(0);
  111.     Q->pv = Q->nx = Q;
  112.     Get_QList (QFILE, Q, size);
  113.  
  114.     wrapwrite (stdout, 0, 0, col, "What is your name?", 0);
  115.     name = clone_line(stdin, 80);
  116.     wrapwrite (stdout, 0, 0, col,
  117.         "If you know your psychological type, please enter it.\n", 0);
  118.     type = clone_line(stdin, 4);
  119.  
  120. #ifdef DEBUG
  121.     wrapwrite (stdout, 0, 0, col,
  122.         "Enter an integer as a seed value for the random # generator", 0);
  123.     srand (fgetp(stdin));
  124. #else
  125.     srand (clock());
  126. #endif
  127.  
  128.     /* Initializes Preference Scores to Zero */
  129.     for (i = 0; i < 14; i++)
  130.         pr[i] = 0;
  131.  
  132.     if (argc > 1)
  133.         read_scores (argv[1], Q);
  134.     Q = RND_QList (Q, size);
  135.     AskQuestions (Q, col);
  136.  
  137.     /* Calculates Scores */
  138.     for (Q = Q->nx; Q->num > 0; Q = Q->nx)
  139.         pr[Q->ans] += Q->strength;
  140.  
  141.     wrapwrite (stdout, 0, 0, col, OUTSTR, 0);
  142.     A = getp(1, OUTMAX);
  143.     if (A == 1)
  144.         fptr = stdout;
  145.     else if (A == 2) {
  146.         wrapwrite (stdout, 0, 0, col, "Please enter a file name.", 0);
  147.         fname = clone_line(stdin, FILE_NAME_MAX);
  148.         WrOpen (fptr, fname);
  149.     }
  150. #if OPSYS != OTHER
  151.     else if (A == 3) {
  152.         WrOpen (fptr, prtdev);
  153.         col = 75;
  154.     }
  155. #endif
  156.  
  157.     E = pr[1]; I = pr[2]; S = pr[3]; N = pr[4];
  158.     T = pr[5]; F = pr[6]; J = pr[7]; P = pr[8];
  159.     ES = pr[12]; EN = pr[13]; ET = pr[11]; EF = pr[10];
  160.     sprintf (nline, "%s's scores on the main set of questions:\n"
  161.                     "\nExtraversion (E): %3d    %3d :(I) Introversion"
  162.                     "\nSensing      (S): %3d    %3d :(N) iNtuition"
  163.                     "\nThinking     (T): %3d    %3d :(F) Feeling"
  164.                     "\nJudging      (J): %3d    %3d :(P) Perceiving\n",
  165.                     name, E, I, S, N, T, F, J, P);
  166.     wrapwrite (fptr, 0, 0, col, nline, 0);
  167.  
  168.     /* Calculates possible life pattern based on primary scores. */
  169.     LP[0] = (E > I) ? 'E' : (E < I) ? 'I' : 'X';
  170.     LP[1] = (S > N) ? 'S' : (S < N) ? 'N' : 'X';
  171.     LP[2] = (T > F) ? 'T' : (T < F) ? 'F' : 'X';
  172.     LP[3] = (J > P) ? 'J' : (J < P) ? 'P' : 'X';
  173.     LP[4] = 0;
  174.  
  175.     fprintf (fptr, "You scored as an %s.\n", LP);
  176.     x = 0;
  177.     for (i = 0; i < 4; i++)
  178.         if (LP[i] == 'X')
  179.             x++;
  180.     if (x) {
  181.         sprintf (line, "This is not a real type. You could be any of "
  182.         "%d different types. Read the type descriptions to determine "
  183.         "which you are.", pow(2,x));
  184.         wrapwrite (fptr, 0, 0, col, line, 0);
  185.     }
  186.     else {
  187.         E = (LP[0] == 'E'); R = ((LP[3] == 'J') == E);
  188.         sprintf (line, "\nAssuming that you are an %s,\n", LP);
  189.         wrapwrite (fptr, 0, 5, col, line, 0);
  190.         sprintf (line, text1, "DOMINANT", XN, R ? JF[LP[2] == 'F'] : PF[LP[1] == 'S']);
  191.         wrapwrite (fptr, 0, 5, col, line, 0);
  192.         sprintf (line, text1, "AUXILIARY", !XN, R ? PF[LP[1] == 'S'] : JF[LP[2] == 'F']);
  193.         wrapwrite (fptr, 0, 5, col, line, 0);
  194.         sprintf (line, text1, "TERTIARY", XN, R ? PF[LP[1] == 'N'] : JF[LP[2] == 'T']);
  195.         wrapwrite (fptr, 0, 5, col, line, 0);
  196.         sprintf (line, text1, "INFERIOR", !XN, R ? JF[LP[2] == 'T'] : PF[LP[1] == 'N']);
  197.         wrapwrite (fptr, 0, 5, col, line, 0);
  198.     }
  199.     if (A == 1) {
  200.         wrapwrite (stdout, 0, 0, col, "Hit <ENTER> or <RETURN> to see",
  201.             "your results on the supplementary questions.", 0);
  202.         while (fgetc(stdin) != '\n');
  203.     }
  204.     sprintf (nline, "\n%s's scores on the supplementary questions:\n\n"
  205.     "Extraverted Thinking / Introverted Feeling   : %d\n"
  206.     "Extraverted Feeling / Introverted Thinking   : %d\n\n"
  207.     "Extraverted Intuition / Introverted Sensing  : %d\n"
  208.     "Extraverted Sensing / Introverted Intuition  : %d\n\n"
  209.     "Rationality (Dominant Judging Function)      : %d\n"
  210.     "A-rationality (Dominant Perceiving Function) : %d\n\n",
  211.         name, ET, EF, EN, ES, pr[9], pr[0]);
  212.     wrapwrite (fptr, 0, 0, col, nline, 0);
  213.  
  214.     /* Calculates possible life patterns based on supplemental scores. */
  215.     LPE[0] = 'E'; LPI[0] = 'I';
  216.     if (pr[9] > pr[0]) {
  217.         LPE[3] = 'J';
  218.         LPI[3] = 'P';
  219.     }
  220.     else if (pr[9] < pr[0]) {
  221.         LPE[3] = 'P';
  222.         LPI[3] = 'J';
  223.     }
  224.     else {
  225.         LPE[3] = 'X';
  226.         LPI[3] = 'X';
  227.     }
  228.     if (LPE[3] == 'P') {
  229.         if (EF > ET) {
  230.             LPE[2] = 'T';
  231.             LPI[2] = 'F';
  232.         }
  233.         else if (EF < ET) {
  234.             LPE[2] = 'F';
  235.             LPI[2] = 'T';
  236.         }
  237.         else {
  238.             LPE[2] = 'X';
  239.             LPI[2] = 'X';
  240.         }
  241.         if (ES < EN) {
  242.             LPE[1] = 'N';
  243.             LPI[1] = 'S';
  244.         }
  245.         else if (ES > EN) {
  246.             LPE[1] = 'S';
  247.             LPI[1] = 'N';
  248.         }
  249.         else {
  250.             LPE[1] = 'X';
  251.             LPI[1] = 'X';
  252.         }
  253.     }
  254.     else if (LPE[3] == 'J') {
  255.         if (EF < ET) {
  256.             LPE[2] = 'T';
  257.             LPI[2] = 'F';
  258.         }
  259.         else if (EF > ET) {
  260.             LPE[2] = 'F';
  261.             LPI[2] = 'T';
  262.         }
  263.         else {
  264.             LPE[2] = 'X';
  265.             LPI[2] = 'X';
  266.         }
  267.         if (ES > EN) {
  268.             LPE[1] = 'N';
  269.             LPI[1] = 'S';
  270.         }
  271.         else if (ES < EN) {
  272.             LPE[1] = 'S';
  273.             LPI[1] = 'N';
  274.         }
  275.         else {
  276.             LPE[1] = 'X';
  277.             LPI[1] = 'X';
  278.         }
  279.     }
  280.     else {
  281.         LPE[1] = 'X';
  282.         LPE[2] = 'X';
  283.         LPI[1] = 'X';
  284.         LPI[2] = 'X';
  285.     }
  286.     LPE[4] = LPI[4] = 0;
  287.  
  288.     sprintf (line, "According to the supplementary scores, %s could be "
  289.     "an %s or an %s.  These are opposite types, because the supplementary "
  290.     "questions measure for preferences that opposite types share in common.  "
  291.     "See the FAQ for an explanation.", name, LPE, LPI);
  292.     if (typecmp(LP, LPE) || typecmp(LP, LPI))
  293.         sprintf (nline, "%s These results are consistent with your score as an %s.", line, LP);
  294.     else
  295.         sprintf (nline, "%s These results conflict with the evaluation of %s as an %s.", line, name, LP);
  296.     wrapwrite (fptr, 5, 0, col, nline, "\n\n", 0);
  297.     if (fptr != stdout)
  298.         fclose (fptr);
  299.  
  300.     wrapwrite (stdout, 5, 0, col,
  301.         "Please note that the DDLI is fallible, and that you might not",
  302.         "be what you scored as.  In order to make the DDLI more",
  303.         "reliable, I want to collect the raw scores from people who know",
  304.         "their type.  With your permission, the DDLI will store your raw",
  305.         "scores in a file.  If you already know your type, or if you",
  306.         "figure out what your type is, please send me your raw scores",
  307.         "via e-mail.  Your raw scores will help me determine which",
  308.         "questions to leave out and which to leave in.  Do you give the",
  309.         "DDLI permission to store your raw scores in a file?", 0);
  310.     if (yes())
  311.         save_scores (Q, type, col);
  312.  
  313.     return 0;
  314. }
  315.  
  316. int pow (int x, int y) {
  317.     if (y < 1)
  318.         return 1;
  319.     if (y == 1)
  320.         return x;
  321.     return x * pow(x, y-1);
  322. }
  323.  
  324. int typecmp (char *t1, char *t2) {
  325.     int i;
  326.  
  327.     for (i = 0; i < 4; i++)
  328.         if ((t1[i] != t2[i]) && (t1[i] != 'X') && (t2[i] != 'X'))
  329.             return 0;
  330.     return 1;
  331. }
  332.